<?php
/*
 * Copyright (c) 2021.  Liuhongbin All rights reserved.
 * @domain http://dkyx.cc
 * @author liuhongbin <514660094@qq.com>
 */

namespace hiduoke\services\formBuilder\element;

use FormBuilder\Driver\CustomComponent;

class ElCollapseItem extends CustomComponent
{

    public function createValidate()
    {
    }

    /**
     * 唯一标志符
     * @param string|int $name
     * @return ElCollapseItem
     */
    public function name($name)
    {
        return $this->props(['name' => $name]);
    }

    /**
     * 面板标题
     * @param string $title 标题名称
     * @param string $icon 图标
     * @param false $is_default 是否默认
     * @return ElCollapseItem
     */
    public function title($title, $icon = '', $is_default = false)
    {
        if (!$title) {
            return $this;
        }
        if ($is_default) {
            return $this->props(['title' => $title]);
        } else {
            if (!$icon) {
                $style = 'width: 8px;height: 20px;background: #409eff;margin-right: 5px;';
            } else {
                $style = 'margin-right:5px;font-size:16px;color: #409eff;';
            }
            return $this->appendChild([
                'type'     => 'b',
                'slot'     => 'title',
                'style'    => 'display: flex;align-items: center;color: #409eff;',
                'children' => [
                    [
                        'type'  => 'i',
                        'style' => $style,
                        'class' => $icon
                    ],
                    $title
                ]
            ]);
        }
    }

    /**
     * 是否禁用
     * @param bool $disabled
     * @return ElCollapseItem
     */
    public function disabled($disabled = true)
    {
        return $this->props(['disabled' => $disabled]);
    }
}
